------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  S:\Research\jmcss\Aggregation\Sims\Aggregation_Cases1234_19March_2022.log
  log type:  text
 opened on:  19 Mar 2022, 14:47:18
r; t=0.04 14:47:18

. *This was created by Aggregation_Cases1234_19March_2022.do
. qui local rep = 10000
r; t=0.00 14:47:18

. qui local n=10000
r; t=0.00 14:47:18

. 
. foreach sigmax of numlist 0 0.20 0.40 { 
  2. foreach sigma  of numlist 0 0.40 0.56 { 
  3. di
  4. di "----------------------------------------------------------------------"
  5. if `sigma'==0&`sigmax'==0 di "CASE 1"
  6. if `sigma'!=0&`sigmax'==0 di "CASE 2"
  7. if `sigma'==0&`sigmax'!=0 di "CASE 3"
  8. if `sigma'!=0&`sigmax'!=0 di "CASE 4"
  9. di "----------------------------------------------------------------------"
 10. di
 11. foreach dgp of numlist 2 { // 1 2 Just use case 2 so that PPML is not optimal
 12. foreach t of numlist 60 { 
 13. 
. clear 
 14. set seed 24022022
 15. qui local obs=`n'*`t'
 16. qui local smpl=max(`obs',`rep')
 17. qui set obs `smpl'
 18. qui g obsr=_n
 19. qui local A=5 
 20. qui local B=2
 21. 
. qui gen ID=1+int((_n-1)/`t') if _n<=`obs'
 22. qui gen T=1+`t'*(((_n-1)/`t')-int((_n-1)/`t')) if _n<=`obs'
 23. qui xtset ID T
 24. 
. qui g bp=. if _n<=`rep'
 25. qui g bg=. if _n<=`rep'
 26. qui g wb0=. if _n<=`rep'
 27. 
. forvalues r = 1/`rep' {
 28. qui g beta=rnormal(0,`sigma') if _n<=`obs'
 29. qui bysort ID: egen betax=mean(beta) if _n<=`obs'
 30. qui replace beta=-1+betax*sqrt(`t')
 31. 
. qui g x=rnormal() if _n<=`obs'
 32. qui bysort ID: egen mx=mean(x) if _n<=`obs'
 33. qui replace x=mx*sqrt(`t')
 34. drop mx
 35. if `sigmax'!=0 qui replace x=rnormal(x,sqrt((1-`sigmax')*(x<0)+(1+`sigmax')*(x>0))) if _n<=`obs'
 36. qui bysort ID: egen mx=mean(x) if _n<=`obs'
 37. 
. if `dgp'<1.5 qui g double y=rchi2(rnbinomial(exp(-ln(`t')+beta*x+0.4)/(`A'-1),1/`A')) if _n<=`obs'
 38. if `dgp'>1.5 qui g double y=rchi2(rnbinomial(1/(`B'*`t'),1/(1+`B'*exp(beta*x+0.4))))  if _n<=`obs'
 39. qui replace y=0 if y==.&_n<=`obs' 
 40. qui bysort ID: egen my=sum(y) if _n<=`obs'
 41. sort obsr
 42. 
. qui g double yb0=y*beta if _n<=`obs'
 43. su yb0 if _n<=`obs', meanonly
 44. local mu0=r(mean)
 45. su y if _n<=`obs', meanonly
 46. qui replace wb0=`mu0'/r(mean) in `r'
 47. 
. qui glm my mx if T==1&_n<=`obs', irls robust link(log) family(poisson)
 48. qui replace bp= _b[mx] in `r'
 49. mat b=e(b)
 50. qui glm my mx if T==1&_n<=`obs', robust link(log) family(gamma) from(b)
 51. if e(converged)==1 qui replace bg= _b[mx] in `r'
 52. 
. drop x y* mx my* beta*  
 53. }
 54. di
 55. di "DGP = `dgp', S = " `sigma' ", Sx = " `sigmax' ", t = " `t' ", n = " `n' ", 
 56. su bp bg wb0 if _n<=`rep'
 57. di "----------------------------------------------------------------------"
 58. di "----------------------------------------------------------------------"
 59. di
 60. }
 61. }
 62. }
 63. }

----------------------------------------------------------------------
CASE 1
----------------------------------------------------------------------


DGP = 2, S = 0, Sx = 0, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -.9996165    .0346672  -1.178443   -.875843
          bg |     10,000   -1.001013    .0289596  -1.133297  -.8751799
         wb0 |     10,000          -1           0         -1         -1
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 2
----------------------------------------------------------------------


DGP = 2, S = .4, Sx = 0, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.174781    .1125146  -2.886508  -.9321031
          bg |     10,000   -1.001667    .0338878  -1.185935  -.8367586
         wb0 |     10,000   -1.185204    .0431158  -1.833936  -1.099154
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 2
----------------------------------------------------------------------


DGP = 2, S = .56, Sx = 0, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.338355    .1634354  -2.723681  -1.009963
          bg |     10,000   -.9972975    .0459975  -1.270678  -.6753796
         wb0 |     10,000   -1.395149    .0902527  -2.277624  -1.219154
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 3
----------------------------------------------------------------------


DGP = 2, S = 0, Sx = .2, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -.9480509    .0479748  -1.381688  -.8105375
          bg |     10,000   -.9235072     .028746  -1.029741  -.8198225
         wb0 |     10,000          -1           0         -1         -1
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .4, Sx = .2, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.173132    .1244737  -2.118336  -.8232948
          bg |     10,000   -1.040683    .0489457  -1.302761  -.6551862
         wb0 |     10,000   -1.322552    .0503544  -1.701084  -1.199636
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .56, Sx = .2, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.251524    .1272898  -2.013104  -.6432435
          bg |     10,000    -1.10152    .0664388  -1.375542   -.392894
         wb0 |     10,000   -1.594724    .0718908   -2.03098  -1.385252
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 3
----------------------------------------------------------------------


DGP = 2, S = 0, Sx = .4, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -.8923627    .0448617  -1.188448   -.743413
          bg |     10,000   -.8468698    .0286271  -.9542584  -.7395873
         wb0 |     10,000          -1           0         -1         -1
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .4, Sx = .4, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000   -1.101541    .1307081  -2.073087  -.5542227
          bg |     10,000   -.9354858    .0500026  -1.181715  -.5342951
         wb0 |     10,000   -1.301422    .0500934   -1.75292  -1.185524
----------------------------------------------------------------------
----------------------------------------------------------------------


----------------------------------------------------------------------
CASE 4
----------------------------------------------------------------------


DGP = 2, S = .56, Sx = .4, t = 60, n = 10000,

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          bp |     10,000     -1.2005    .1432494  -2.016392  -.5109974
          bg |     10,000    -.986379    .0692987  -1.309953   -.343677
         wb0 |     10,000   -1.574918    .0747164  -2.059201    -1.3477
----------------------------------------------------------------------
----------------------------------------------------------------------

r; t=455215.38 21:14:19

. capture log close
